package com.qn;

import com.alibaba.fastjson.JSON;
import com.only4play.order.commons.constants.BizEnum;
import com.only4play.order.commons.filters.selector.FilterSelector;
import com.only4play.order.commons.filters.selector.LocalListBasedFilterSelector;
import com.qn.pipeline2.FilterChainPipeline;
import com.qn.pipeline2.context.InstanceBuildContext;
import com.qn.pipeline2.filters.InputDataPreCheckerFilter;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@SpringBootTest
@Slf4j
class Pipeline2 {

    @Resource
    private FilterChainPipeline exchangeInvoicePipeline;

    @Test
    public void test_AuthLink() {
        Map<String, Object> formInput = new HashMap<>();
        formInput.put("instanceName", "123456");

        FilterSelector selector = getExchangeSelector();
        InstanceBuildContext data = new InstanceBuildContext(BizEnum.BIZ_XXX,selector);
        data.setFormInput(formInput);

        exchangeInvoicePipeline.getFilterChain().handle(data);

        log.info(JSON.toJSONString(data));
    }

    /**
     * 配置要加载的filter
     * @return
     */
    private FilterSelector getExchangeSelector() {
        LocalListBasedFilterSelector selector = new LocalListBasedFilterSelector();
        selector.addFilter(InputDataPreCheckerFilter.class.getSimpleName());
        return selector;
    }
}
